package bookSystem.operations;

import bookSystem.book.Book;
import bookSystem.book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    //添加图书--管理员操作
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("添加图书");

        System.out.print("书名：");
        String name = scanner.nextLine();//书名

        System.out.print("作者：");
        String author = scanner.nextLine();//作者

        System.out.print("类型：");
        String type = scanner.nextLine();//类型

        System.out.print("价格：");
        int price = scanner.nextInt();//价格

        Book book = new Book(name,author,price,type);
        int size = bookList.getUsedSize();

        for (int i = 0; i < size; i++) {
            if(bookList.getBook(i).getName().equals(name)) {
                System.out.println("书架存在这种书，不能进行添加！");
                return;
            }
        }

        bookList.setBooks(size,book);
        bookList.setUsedSize(size+1);
        System.out.println("添加成功");
    }
}
